<template>
  <div class="cardList-form">
    <div class="widget_settings">
      <template v-for="(item, index) in formData">
        <div class="card_group" :key="index">
          <div class="card_group_name">{{ item.cardAddCategoryName  || '素材' }}</div>
          <div class="card_items">
            <template v-for="(sitem, sindex) in item.cardVOList">
              <div class="card" :key="sindex" @click="addCard(sitem.cardId)">
                <div class="card_icon">
                  <i class="jyfont" :class="`jy-${sitem.cardTypeCode}`"></i>
                </div>
                <h2 class="card_name">{{ sitem.cardName }}</h2>
              </div>
            </template>
          </div>
        </div>
      </template>
    </div>
  </div>
</template>

<script>
import mock from '@/constants/themeMock';

export default {
    name: 'cardListForm',
    props: {
        value: {
            type: Array,
            default: () => []
        }
    },
    data () {
        return {
            formData: this.$props.value,
            cartList: []
        };
    },
    mounted () {
        this.cartList = mock.cardList;
    },
    methods: {
        addCard (id) {
            this.$store.commit('SET_ADD_CARD_ID', {id, text: Math.random() * 10000});
        }
    }
};
</script>

<style scoped lang="scss">
.card_group{
  &_name{
    height: 56px;
    line-height: 56px;
    color: #212121;
    font-size: 16px;
    font-weight: 500;
    padding-left: 20px;
    background: #f6f7f9;
  }
  .card_items{
    margin: 0 10px;
    display: flex;
    flex-wrap: wrap;
    padding-top: 10px;
    .card{
      position: relative;
      border: 1px solid rgba(0, 0, 0, 0);
      width: 33.33%;
      margin-bottom: 10px;
      cursor: pointer;
      .card_icon{
        width: 100%;
        height: 46.8px;
        position: relative;
        border-radius: 3px;
        display: flex;
        justify-content: center;
        overflow: hidden;
        align-items: center;
        i{
          font-size: 30px;
          color: #8490b4;
        }
      }
      .card_name {
        font-size: 14px;
        width: 100%;
        text-align: center;
        bottom: 10px;
        line-height: 17px;
        margin-top: 3px;
        font-weight: normal;
        text-overflow: ellipsis;
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        white-space: pre-wrap;
      }
    }
  }
}
</style>
